package com.metadata_system.api.filter;

import javax.servlet.*;
import java.io.IOException;
import java.util.Date;

//@Component
//@Slf4j
public class TimerFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
//        System.out.println("过滤器-初始化");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        // 执行下个过滤器
        long startTime = new Date().getTime();
        servletRequest.setAttribute("startTime", startTime);
//        UrlResponseWrapper responseWrapper = new UrlResponseWrapper((HttpServletResponse) servletResponse);
        filterChain.doFilter(servletRequest, servletResponse);
//        long execTime = new Date().getTime() - startTime;
//        System.out.println("控制器方法-执行时间: " + execTime + "毫秒");
    }

    @Override
    public void destroy() {
//        System.out.println("过滤器-销毁");
    }
}
